# -*- coding: utf-8 –*-

import datetime

from mongoengine import StringField, IntField, EmailField, BooleanField, \
    DateTimeField, ListField, EmbeddedDocumentField, ObjectIdField, \
    ReferenceField, Document, EmbeddedDocument, URLField, DecimalField, signals,\
    FileField

from app.constants import GDS_ORDER_STATUS
from .plan import PlanOrderMtu, UserPlan
from .order import Payment


class Hotel(Document):
    '''
    MTU酒店信息：存储第三方酒店基本信息
    酒店星级目前存放在mtu表中
    备注：该信息由gds系统定期导入
    '''

    name = StringField(max_length=100)
    price = DecimalField()
    is_active = BooleanField(default=True)
    date_added = DateTimeField(default=datetime.datetime.utcnow)
    gds_hotel_id = StringField(max_length=50)

    meta = {
        'collection': 'vacation_hotel',
        'indexes': ['gds_hotel_id']
    }


class HotelProductOrder(Document):
    """
    GDS 酒店订单
    """
    # 在特定行程(UserPlan)下预订酒店(非直接预订)
    # 需要关联到 UserPlan 和 PlanOrderMtu
    # plan = ReferenceField(UserPlan, null=True)
    planordermtu = ReferenceField(PlanOrderMtu, null=True)

    # 提交订单时:
    user_id = IntField(null=True)
    device_id = StringField(null=True)
    identity = StringField(max_length=50)
    hotel_id = StringField(max_length=50)
    product_id = StringField(max_length=50)
    hotel_name = StringField(max_length=500, null=True)
    product_name = StringField(max_length=500, null=True)
    hotel_country = StringField(max_length=200, null=True)
    hotel_city = StringField(max_length=200, null=True)

    checkin_date = DateTimeField()
    checkout_date = DateTimeField()
    rooms = StringField(max_length=1000)
    contact_mobile = StringField(max_length=50)
    contact_email = EmailField()

    customer_preferences = StringField(max_length=10, null=True)
    invoice_title = StringField(max_length=100, null=True)

    # 创建订单成功后:
    order_id = StringField(max_length=50, unique=True)
    total_price = DecimalField()
    datetime_created = DateTimeField(default=datetime.datetime.utcnow)
    datetime_updated = DateTimeField(default=datetime.datetime.utcnow)

    # 订单状态:
    status = StringField(default=GDS_ORDER_STATUS['NEW'])

    # 支付相关
    payment = ReferenceField(Payment, null=True)

    meta = {
        'collection': 'vacation_hotelproductorder',
    }
